﻿#include "execsql.h"

#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlTableModel>
#include <QDebug>

//////////////////////////////////////////UserInfo///////////////////////////////////////////////
void ExecSQL::searchAllUserInfos()
{
    QString queryString = QString("select * from user");
    qDebug() << queryString;
    updateUserInfoList(queryString);
}
void ExecSQL::searchAllUserInfosForRole(const QString &role)
{
    QString queryString = QString("select * from user where u_role = %1").arg(role);
    qDebug() << queryString;
    updateUserInfoList(queryString);
}

void ExecSQL::searchUserInfoForID(const QString &value)
{
    QString queryString = QString("select * from user where u_user = '%1'").arg(value);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForName(const QString &value)
{
    QString queryString = QString("select * from user where u_name = '%1'").arg(value);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForSex(const QString &value)
{
    QString queryString = QString("select * from user where u_sex = '%1'").arg(value);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForCertState(const QString &value)
{
    QString queryString = QString("select * from user where u_certificate like '%%1%'").arg(value);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForRealName(const QString &value)
{
    QString queryString = QString("select * from user where u_realName = '%1'").arg(value);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForEmail(const QString &value)
{
    QString queryString = QString("select * from user where u_email = '%1'").arg(value);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForPhone(const QString &value)
{
    QString queryString = QString("select * from user where u_phone = '%1'").arg(value);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}

void ExecSQL::searchUserInfoForIDAndRole(const QString &value, const QString &role)
{
    QString queryString = QString("select * from user where u_user = '%1' and u_role = %2").arg(value).arg(role);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForNameAndRole(const QString &value, const QString &role)
{
    QString queryString = QString("select * from user where u_name = '%1' and u_role = %2").arg(value).arg(role);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForSexAndRole(const QString &value, const QString &role)
{
    QString queryString = QString("select * from user where u_sex = '%1' and u_role = %2").arg(value).arg(role);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForRealNameAndRole(const QString &value, const QString &role)
{
    QString queryString = QString("select * from user where u_realName = '%1' and u_role = %2").arg(value).arg(role);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForEmailAndRole(const QString &value, const QString &role)
{
    QString queryString = QString("select * from user where u_email = '%1' and u_role = %2").arg(value).arg(role);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}
void ExecSQL::searchUserInfoForPhoneAndRole(const QString &value, const QString &role)
{
    QString queryString = QString("select * from user where u_phone = '%1' and u_role = %2").arg(value).arg(role);
    qDebug() << queryString;

    updateUserInfoList(queryString);
}

bool ExecSQL::modifyUserInfoForPswd(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_psd = '%1' where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForCertPath(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_cert_path = '%1' where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForName(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_name = '%1' where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForRole(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_role = %1 where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForSex(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_sex = '%1' where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForCertState(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString;
    if (value == "")
    {
        queryString = QString("update user set u_certificate = '', u_idCardNum = '', u_realName = '' where u_user = '%1'").arg(id);
    }
    else
    {
        queryString = QString("update user set u_certificate = '%1' where u_user = '%2'").arg(value).arg(id);
    }
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForRealName(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_realName = '%1' where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForBirthday(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_birth = '%1' where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForPhone(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_phone = '%1' where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForEmail(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_email = '%1' where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyUserInfoForHeadPic(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update user set u_head_pic = '%1' where u_user = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::deleteUserInfo(const QString &id)
{
    QSqlQuery query;
    QString queryString = QString("delete from user where u_user = '%1'").arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::addNewUserInfo(const UserInfo &info)
{
    QSqlQuery query;
    QString queryString = QString("insert into user "
                                  "(u_user,u_psd, u_role,u_head_pic,u_sex,u_name,u_phone,u_birth)"
                                  " values('%1', '%2', %3, '%4', '%5', '%6', '%7', '%8')")
            .arg(info.getNumber()).arg(info.getPassword()).arg(info.getRole()).arg(info.getHeadPic())
            .arg(info.getSex()).arg(info.getName()).arg(info.getPhone()).arg(info.getBirthday());
    qDebug() << queryString;
    return query.exec(queryString);
}
void ExecSQL::updateUserInfoList(const QString &sql)
{
    GlobalVars::g_userInfoMap.clear();
    GlobalVars::g_userInfoList->clear();

    QSqlQuery query;
    if(query.exec(sql))
    {
         int id_idx = query.record().indexOf("u_user");
         int pswd_idx = query.record().indexOf("u_psd");
         int role_idx = query.record().indexOf("u_role");
         int headPic_idx = query.record().indexOf("u_head_pic");

         int name_idx = query.record().indexOf("u_name");
         int realName_idx = query.record().indexOf("u_realName");
         int certPath_idx = query.record().indexOf("u_cert_path");
         int sex_idx = query.record().indexOf("u_sex");

         int birth_idx = query.record().indexOf("u_birth");
         int phone_idx = query.record().indexOf("u_phone");
         int email_idx = query.record().indexOf("u_email");
         int certificate_idx = query.record().indexOf("u_certificate");

        while(query.next())
        {
            QString id = query.value(id_idx).toString();
            QString pswd = query.value(pswd_idx).toString();
            QString role = query.value(role_idx).toString();
            QString headPic = query.value(headPic_idx).toString();

            QString name = query.value(name_idx).toString();
            QString realName = query.value(realName_idx).toString();
            QString certPath = query.value(certPath_idx).toString();
            QString sex = query.value(sex_idx).toString();

            QString birth = query.value(birth_idx).toString();
            QString phone = query.value(phone_idx).toString();
            QString email = query.value(email_idx).toString();
            QString certificate = query.value(certificate_idx).toString();

//            qDebug() << id << ", " << certificate << ", " << role << ", " << sex
//                         << ", " << name << ", " << birth << ", " << phone << ", " << email
//                         << ", " << headPic << ", " << idCard << ", " << realName;
            UserInfo info(id, pswd, role,sex,name,birth,phone,email,headPic,certificate,certPath,realName);
            GlobalVars::g_userInfoList->append(info);
        }

         for(UserInfoList::iterator it = GlobalVars::g_userInfoList->begin();
             it != GlobalVars::g_userInfoList->end(); it++)
         {
            GlobalVars::g_userInfoMap.insert(it->getNumber(), it);
         }
    }
}

///////////////////////////////////////////////HotelInfo///////////////////////////////////////////////
void ExecSQL::searchAllHotelInfos()
{
    QString queryString = QString("select * from hotel");
    qDebug() << queryString;
    updateHotelInfoList(queryString);
}
void ExecSQL::updateHotelInfoList(const QString &sql)
{
    GlobalVars::g_hotelInfoMap.clear();
    GlobalVars::g_hotelInfoList->clear();

    QSqlQuery query;
    if(query.exec(sql))
    {
         int id_idx = query.record().indexOf("h_hotel");
         int user_idx = query.record().indexOf("h_user");
         int name_idx = query.record().indexOf("h_name");
         int state_idx = query.record().indexOf("h_state");
         int server_idx = query.record().indexOf("h_server");

         int location_idx = query.record().indexOf("h_location");
         int star_idx = query.record().indexOf("h_star");
         int type_idx = query.record().indexOf("h_type");
         int city_idx = query.record().indexOf("h_city");
         int decoratedTime_idx = query.record().indexOf("h_decorated_time");

         int openedTime_idx = query.record().indexOf("h_opened_time");
         int totalHouse_idx = query.record().indexOf("h_total_house");
         int lowPrice_idx = query.record().indexOf("h_low_price");
         int highPrice_idx = query.record().indexOf("h_high_price");
         int phone_idx = query.record().indexOf("h_phone");

         int mark_idx = query.record().indexOf("h_mark");
         int commentCount_idx = query.record().indexOf("h_comment_count");
         int businessLicense_idx = query.record().indexOf("h_business_license");
         int photo_idx = query.record().indexOf("h_photo");
         int description_idx = query.record().indexOf("h_description");

         int cancellation_idx = query.record().indexOf("h_cancellation");
         int instruction_idx = query.record().indexOf("h_instruction");

        while(query.next())
        {
            QString id = query.value(id_idx).toString();
            QString user = query.value(user_idx).toString();
            QString name = query.value(name_idx).toString();
            QString state = query.value(state_idx).toString();
            QString server = query.value(server_idx).toString();

            QString location = query.value(location_idx).toString();
            QString star = query.value(star_idx).toString();
            QString type = query.value(type_idx).toString();
            QString city = query.value(city_idx).toString();
            QString decoratedTime = query.value(decoratedTime_idx).toString();

            QString openedTime = query.value(openedTime_idx).toString();
            QString phone = query.value(phone_idx).toString();
            QString totalHouse = query.value(totalHouse_idx).toString();
            QString lowPrice = query.value(lowPrice_idx).toString();
            QString highPrice = query.value(highPrice_idx).toString();

            QString description = query.value(description_idx).toString();
            QString mark = query.value(mark_idx).toString();
            QString commentCount = query.value(commentCount_idx).toString();
            QString businessLicense = query.value(businessLicense_idx).toString();
            QString photo = query.value(photo_idx).toString();

            QString cancellation = query.value(cancellation_idx).toString();
            QString instruction = query.value(instruction_idx).toString();
//            qDebug() << id << ", " << user << ", " << name << ", " << state
//                         << ", " << location << ", " << star << ", " << type << ", " << city
//                         << ", " << phone << ", " << description << ", " << photo;

            HotelInfo info(id, user, name,location,star,type,city,phone,totalHouse.toInt(),lowPrice.toInt(),
                           highPrice.toInt(),openedTime,decoratedTime,description,cancellation,instruction,
                           server,businessLicense,photo,state,mark, commentCount.toInt());
            GlobalVars::g_hotelInfoList->append(info);
        }

         for(HotelInfoList::iterator it = GlobalVars::g_hotelInfoList->begin();
             it != GlobalVars::g_hotelInfoList->end(); it++)
         {
            GlobalVars::g_hotelInfoMap.insert(it->getHotel(), it);
         }
//         qDebug() << GlobalVars::g_hotelInfoList->size();
    }
}
void ExecSQL::searchHotelInfoForMoreCondition(const QVector< QVector<QString> > &doubleArray)
{
    /// doubleArray index textIndex text
    /// doubleArray [0]  type    text                doubleArray [4]  city      text     doubleArray [8]  outTime   text
    /// doubleArray [1]   star    text                doubleArray [5]  name    text     doubleArray [9]  location   text
    /// doubleArray [2]   mark  index text      doubleArray [6]  price    text
    /// doubleArray [3]   select index text      doubleArray [7]  inTime text
    QString sql = "select * from hotel where ";
    qDebug() << " doubleArray.size() = " <<  doubleArray.size();
    for(int i = 0; i < doubleArray.size(); i++)
    {
        if (doubleArray[i][0].isEmpty())
        {
            continue;
        }
        qDebug() << doubleArray[i][0];
        switch (doubleArray[i][0].toInt())///判断哪个下拉键选中条件
        {
            case H_Select:
                switch (doubleArray[H_Select][1].toInt())
                {
                    case H_Sel_Number:
                        sql += ("h_hotel like '%" + doubleArray[H_Select][2] + "%' and "); break;
                    case H_Sel_Name:
                        sql += ("h_name like '%" + doubleArray[H_Select][2] + "%' and "); break;
                    case H_Sel_City:
                        sql += ("h_city like '%" + doubleArray[H_Select][2] + "%' and "); break;
                    case H_Sel_User:
                        sql += ("h_user like '%" + doubleArray[H_Select][2] + "%' and "); break;
                    case H_Sel_Location:
                        sql += ("h_location like '%" + doubleArray[H_Select][2] + "%' and "); break;
                    default: break;
                }
                break;
            case H_Type:
            {
                int size = doubleArray[H_Type].size();
                if (size == 1)
                {
                    sql += ("h_type = '" + doubleArray[H_Type][1] + "' and ");
                }
                else{
                    for (int j = 1; j < size; j++)
                    {
                        sql += ("h_type = '" + doubleArray[H_Type][j] + "' or ");
                    }
                    sql += (" 0 and ");
                }
            }  break;
            case H_Star:
            {
                int size = doubleArray[H_Star].size();
                if (size == 1)
                {
                    sql += ("h_star = '" + doubleArray[H_Star][1] + "' and ");
                }
                else{
                    for (int j = 1; j < size; j++)
                    {
                        sql += ("h_star = '" + doubleArray[H_Star][j] + "' or ");
                    }
                    sql += (" 0 and ");
                }
            }  break;
            case H_Mark:
                if (doubleArray[H_Mark][1].toInt() == HML_4_0)
                {
                    sql += ("h_mark < " + doubleArray[H_Mark][2] + " and ");
                }else
                {
                    sql += ("h_mark >= " + doubleArray[H_Mark][2] + " and ");
                }
                break;
            case H_City:
                sql += ("h_city like '%" + doubleArray[H_City][1] + "%' and "); break;
            case H_NameOrLocation:
                sql += ("h_name like '%" + doubleArray[H_NameOrLocation][1] + "%' or "
                        + "h_location like '%" + doubleArray[H_NameOrLocation][1] + "%' and "); break;
            case H_Price:
            {
                QStringList valueList = doubleArray[H_Price][1] .split("-");
                if (valueList.at(1).isEmpty())
                {
                    sql += ("h_low_price >= " + valueList.at(0) + " and ");
                }else
                {
                    sql += ("h_low_price >= " + valueList.at(0) +
                            " and h_low_price <= "  + valueList.at(1) + " and ");
                }
            } break;
//            case H_InTime:
//                sql += ("h_name like '%" + doubleArray[H_InTime][2] + "%' and "); break;
//            case H_OutTime:
//                sql += ("h_name like '%" + doubleArray[H_OutTime][2] + "%' and "); break;
            default: break;
        }
    }
    sql += "1";
    qDebug() << sql;

    updateHotelInfoList(sql);
}

void ExecSQL::searchHotelInfoForNumber(const QString &value)
{
    QString queryString = QString("select * from hotel where h_hotel = '%1'").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForName(const QString &value)
{
    QString queryString = QString("select * from hotel where h_name like '%%1%'").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForCity(const QString &value)
{
    QString queryString = QString("select * from hotel where h_city like '%%1%'").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForLocation(const QString &value)
{
    QString queryString = QString("select * from hotel where h_location like '%%1%'").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForType(const QString &value)
{
    QString queryString = QString("select * from hotel where h_type = '%1'").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForStar(const QString &value)
{
    QString queryString = QString("select * from hotel where h_star = '%1'").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForGreaterMark(const QString &value)
{
    QString queryString = QString("select * from hotel where h_mark >= %1").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForLesserMark(const QString &value)
{
    QString queryString = QString("select * from hotel where h_mark < %1").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForCommentCount(const QString &value)
{
    QString queryString = QString("select * from hotel where h_comment_count > %1").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForUser(const QString &value)
{
    QString queryString = QString("select * from hotel where h_user = '%1'").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForPhone(const QString &value)
{
    QString queryString = QString("select * from hotel where h_phone like '%%1%'").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForState(const QString &value)
{
    QString queryString = QString("select * from hotel where h_state like '%%1%'").arg(value);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}
void ExecSQL::searchHotelInfoForLowPrice(const QString &value1, const QString &value2)
{
    QString queryString = QString("select * from hotel where h_low_price >= %1 "
                                  "and h_low_price <= %2").arg(value1).arg(value2);
    qDebug() << queryString;

    updateHotelInfoList(queryString);
}

bool ExecSQL::modifyHotelInfoForName(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_name = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForCity(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_city = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForUser(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_user = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForPhone(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_phone = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForLocation(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_location = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForType(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_type = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForStar(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_star = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForMark(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_mark = %1 where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForCommentCount(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_comment_count = %1 where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForPhoto(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_photo = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForLicense(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_business_license"
                                  " = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForCount(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_total_house = %1 where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForLowPrice(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_low_price = %1 where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForHighPrice(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_high_price = %1 where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForOpenedTime(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_opened_time = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForDecoratedTime(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_decorated_time = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForCancel(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_cancellation = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForServer(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_server = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForIntroduce(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_instruction = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForDescription(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_description = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHotelInfoForState(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update hotel set h_state = '%1' where h_hotel = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}

bool ExecSQL::deleteHotelInfo(const QString &id)
{
    QSqlQuery query;
    QString queryString = QString("delete from hotel where h_hotel = '%1'").arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::addNewHotelInfo(const HotelInfo &info)
{
    QSqlQuery query;
    QString queryString = QString("insert into hotel "
                                  "(h_hotel,h_name, h_city,h_location,h_type,h_star,h_user,h_phone,"
                                  "h_total_house,h_low_price,h_high_price,h_description,h_cancellation,"
                                  "h_instruction,h_server, h_state,h_opened_time, h_decorated_time) values"
                                  "('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', %9, %10, %11, '%12', '%13',"
                      " '%14', '%15','%16', '%17', '%18')").arg(info.getHotel()).arg(info.getName()).arg(info.getCity())
            .arg(info.getLocation()).arg(info.getType()).arg(info.getStar()).arg(info.getUser()).arg(info.getPhone())
            .arg(info.getTotalHouse()).arg(info.getLowPrice()).arg(info.getHighPrice()).arg(info.getDescription())
            .arg(info.getCancellation()).arg(info.getInstruction()).arg(info.getServer()).arg(info.getState())
            .arg(info.getOpenedTime()).arg(info.getDecoratedTime());
    qDebug() << queryString;
    return query.exec(queryString);
}

///////////////////////////////////////////////HouseInfo///////////////////////////////////////////////
void ExecSQL::searchAllHouseInfos()
{
    QString queryString = QString("select * from house");
    qDebug() << queryString;
    updateHouseInfoList(queryString);
}
void ExecSQL::searchHouseInfosForHotel(const QString &value)
{
    QString queryString = QString("select * from house where h_hotel = '%1'").arg(value);
    qDebug() << queryString;

    updateHouseInfoList(queryString);
}
void ExecSQL::searchHouseInfosForID(const QString &value)
{
    QString queryString = QString("select * from house where h_house = '%1'").arg(value);
    qDebug() << queryString;

    updateHouseInfoList(queryString);
}

bool ExecSQL::modifyHouseInfoForPhoto(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_photo = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForType(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_type = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForPrice(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_price = %1 where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForCount(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_count = %1 where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForArea(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_area = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForCapacity(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_capacity = %1 where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForBedType(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_bed_type = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForBathroom(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_bathroom = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForWindow(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_window = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForNet(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_net = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForBreakfast(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_breakfast = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForMedia(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_media = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForBathroomAcc(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_bathroom_acc = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyHouseInfoForIsFull(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update house set h_is_full = '%1' where h_house = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}

void ExecSQL::updateHouseInfoList(const QString &sql)
{
    GlobalVars::g_houseInfoMap.clear();
    GlobalVars::g_houseInfoList->clear();

    QSqlQuery query;
    if(query.exec(sql))
    {
         int house_idx = query.record().indexOf("h_house");
         int hotel_idx = query.record().indexOf("h_hotel");
         int count_idx = query.record().indexOf("h_count");
         int isFull_idx = query.record().indexOf("h_is_full");

         int type_idx = query.record().indexOf("h_type");
         int price_idx = query.record().indexOf("h_price");
         int photo_idx = query.record().indexOf("h_photo");
         int bedType_idx = query.record().indexOf("h_bed_type");
         int window_idx = query.record().indexOf("h_window");

         int area_idx = query.record().indexOf("h_area");
         int net_idx = query.record().indexOf("h_net");
         int breakfast_idx = query.record().indexOf("h_breakfast");
         int media_idx = query.record().indexOf("h_media");
         int capacity_idx = query.record().indexOf("h_capacity");
         int bathroom_idx = query.record().indexOf("h_bathroom");
         int bathroomAcc_idx = query.record().indexOf("h_bathroom_acc");

        while(query.next())
        {
            QString houseID = query.value(house_idx).toString();
            QString hotelID = query.value(hotel_idx).toString();
            int count = query.value(count_idx).toInt();
            QString isFull = query.value(isFull_idx).toString();

            QString houseType = query.value(type_idx).toString();
            int price = query.value(price_idx).toInt();
            QString photo = query.value(photo_idx).toString();
            QString bedType = query.value(bedType_idx).toString();
            QString window = query.value(window_idx).toString();

            QString area = query.value(area_idx).toString();
            QString net = query.value(net_idx).toString();
            QString breakfast = query.value(breakfast_idx).toString();
            QString media = query.value(media_idx).toString();
            int capacity = query.value(capacity_idx).toInt();
            QString bathroom = query.value(bathroom_idx).toString();
            QString bathroomAcc = query.value(bathroomAcc_idx).toString();

//            qDebug() << price << ", " << count << ", " << houseID << ", " << hotelID
//                         << ", " << isFull << ", " << houseType << ", " << photo << ", " << bedType
//                         << ", " << window << ", " << area << ", " << capacity
//                        << ", " << bathroom << ", " << ", " << bathroomAcc;

            HouseInfo house(houseID, hotelID,houseType,price, count, area, capacity,
                            bedType ,bathroom,window, net, breakfast, media,bathroomAcc,isFull, photo);
            GlobalVars::g_houseInfoList->append(house);
        }

         for(HouseInfoList::iterator it = GlobalVars::g_houseInfoList->begin();
             it != GlobalVars::g_houseInfoList->end(); it++)
         {
            GlobalVars::g_houseInfoMap.insert(it->getHouse(), it);
         }
//         qDebug() << GlobalVars::g_houseInfoList->size();
    }
}
bool ExecSQL::deleteHouseInfo(const QString &id)
{
    QSqlQuery query;
    QString queryString = QString("delete from house where h_house = '%1'").arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::addNewHouseInfo(const HouseInfo &info)
{
    QSqlQuery query;
    QString queryString = QString("insert into house "
                                  "(h_house, h_hotel, h_price, h_count, h_type, h_bed_type, h_capacity"
                                  ",h_area, h_net, h_window, h_breakfast, h_media, h_is_full, h_photo, "
                                  "h_bathroom, h_bathroom_acc) values('%1', '%2', %3, %4, '%5',"
                                  " '%6', %7, '%8', '%9', '%10','%11', '%12', '%13', '%14', '%15', '%16')")
                                .arg(info.getHouse()).arg(info.getHotel()).arg(info.getPrice()).arg(info.getCount())
                                .arg(info.getType()).arg(info.getBedType()).arg(info.getCapacity())
                                .arg(info.getArea()).arg(info.getNet()).arg(info.getWindow())
                                .arg(info.getBreakfast()).arg(info.getMedia()).arg(info.getIsFull())
                                .arg(info.getPhoto()).arg(info.getBathroom()).arg(info.getBathroomAcc());
    qDebug() << queryString;
    return query.exec(queryString);
}

///////////////////////////////////////////////ReserveInfo///////////////////////////////////////////////
void ExecSQL::searchAllReserveInfos()
{
    QString queryString = QString("select * from reserve");
    qDebug() << queryString;
    updateReserveInfoList(queryString);
}
void ExecSQL::searchReserveInfosForHotel(const QString &value)
{
    QString queryString = QString("select * from reserve where r_hotel = '%1'").arg(value);
    qDebug() << queryString;

    updateReserveInfoList(queryString);
}
void ExecSQL::searchReserveInfosForUser(const QString &value)
{
    QString queryString = QString("select * from reserve where r_user = '%1'").arg(value);
    qDebug() << queryString;

    updateReserveInfoList(queryString);
}
void ExecSQL::searchReserveInfosForID(const QString &value)
{
    QString queryString = QString("select * from reserve where r_reserve = '%1'").arg(value);
    qDebug() << queryString;

    updateReserveInfoList(queryString);
}
void ExecSQL::updateReserveInfoList(const QString &sql)
{
    GlobalVars::g_reserveInfoMap.clear();
    GlobalVars::g_reserveInfoList->clear();

    QSqlQuery query;
    if(query.exec(sql))
    {
         int reserve_idx = query.record().indexOf("r_reserve");
         int user_idx = query.record().indexOf("r_user");
         int hotel_idx = query.record().indexOf("r_hotel");
         int houseType_idx = query.record().indexOf("r_house_type");
         int reserveTime_idx = query.record().indexOf("r_reserve_time");

         int checkInTime_idx = query.record().indexOf("r_check_in_time");
         int checkOutTime_idx = query.record().indexOf("r_check_out_time");
         int payment_idx = query.record().indexOf("r_payment");
         int checkInName_idx = query.record().indexOf("r_check_in_name");
         int checkInTel_idx = query.record().indexOf("r_check_in_tel");

         int arrivalTime_idx = query.record().indexOf("r_arrival_time");
         int houseCount_idx = query.record().indexOf("r_house_count");
         int comment_idx = query.record().indexOf("r_comment");
         int state_idx = query.record().indexOf("r_state");

         int hotelName_idx = query.record().indexOf("r_hotel_name");
         int hotelLocation_idx = query.record().indexOf("r_hotel_location");
         int hotelPhone_idx = query.record().indexOf("r_hotel_phone");

        while(query.next())
        {
            QString reserve = query.value(reserve_idx).toString();
            QString user = query.value(user_idx).toString();
            QString hotel = query.value(hotel_idx).toString();
            QString houseType = query.value(houseType_idx).toString();

            QString reserveTime = query.value(reserveTime_idx).toString();
            QString checkInTime = query.value(checkInTime_idx).toString();
            QString checkOutTime = query.value(checkOutTime_idx).toString();
            int payment = query.value(payment_idx).toInt();

            QString checkInName = query.value(checkInName_idx).toString();
            QString checkInTel = query.value(checkInTel_idx).toString();
            QString arrivalTime = query.value(arrivalTime_idx).toString();

            int houseCount = query.value(houseCount_idx).toInt();
            QString comment = query.value(comment_idx).toString();
            QString state = query.value(state_idx).toString();

            QString hotelName = query.value(hotelName_idx).toString();
            QString hotelLocation = query.value(hotelLocation_idx).toString();
            QString hotelPhone = query.value(hotelPhone_idx).toString();
//            qDebug() << reserve << ", " << user << ", " << hotel << ", " << houseType
//                         << ", " << reserveTime << ", " << checkInTime << ", " << checkOutTime
//                         << ", " << payment << ", "  << houseCount << ", "<< checkInName << ", "
//                         << checkInTel<< ", " << arrivalTime << ", " << comment << ", "<< state
//                            << ", "<< hotelName << ", "<< hotelLocation << ", "<< hotelPhone;

            ReserveInfo info(payment,houseCount,reserve,user,hotel,houseType,reserveTime,
                             checkInTel, checkInName,checkInTime, checkOutTime,arrivalTime,state,
                             hotelName,hotelLocation,hotelPhone,comment);

            GlobalVars::g_reserveInfoList->append(info);
        }

         for(ReserveInfoList::iterator it = GlobalVars::g_reserveInfoList->begin();
             it != GlobalVars::g_reserveInfoList->end(); it++)
         {
            GlobalVars::g_reserveInfoMap.insert(it->getReserve(), it);
         }
//         qDebug() << GlobalVars::g_reserveInfoList->size();
    }
}

bool ExecSQL::modifyReserveInfoForState(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update reserve set r_state = '%1' where r_reserve = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyReserveInfoForCommentState(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update reserve set r_comment = '%1' where r_reserve = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}

bool ExecSQL::deleteReserveInfo(const QString &id)
{
    QSqlQuery query;
    QString queryString = QString("delete from reserve where r_reserve = '%1'").arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::addNewReserveInfo(const ReserveInfo &info)
{
    QSqlQuery query;
    QString queryString = QString("insert into reserve "
                                  "(r_reserve, r_user, r_hotel, r_house_type, r_reserve_time, r_check_in_time, r_check_out_time"
                                  ",r_payment, r_check_in_name, r_check_in_tel, r_arrival_time, r_house_count, r_comment, r_state, "
                                  "r_hotel_name, r_hotel_location, r_hotel_phone) values('%1', '%2', '%3', '%4', '%5', "
                                  "'%6', '%7', %8, '%9', '%10', '%11', %12, '%13', '%14','%15','%16','%17')")
            .arg(info.getReserve()).arg(info.getuser()).arg(info.getHotel()).arg(info.getHouseType())
            .arg(info.getReserveTime()).arg(info.getCheckInTime()).arg(info.getCheckOutTime()).arg(info.getPayment())
            .arg(info.getCheckInName()).arg(info.getCheckInTel()).arg(info.getArrivalTime()).arg(info.getHouseCount())
            .arg(info.getCommentState()).arg(info.getState()).arg(info.getHotelName()).arg(info.getHotelLocation())
            .arg(info.getHotelPhone());
    qDebug() << queryString;
    return query.exec(queryString);
}


///////////////////////////////////////////////CommentInfo///////////////////////////////////////////////
void ExecSQL::searchAllCommentInfos()
{
    QString queryString = QString("select * from comment");
    qDebug() << queryString;
    updateCommentInfoList(queryString);
}
void ExecSQL::searchCommentInfosForHotel(const QString &value)
{
    QString queryString = QString("select * from comment where c_hotel = '%1'").arg(value);
    qDebug() << queryString;

    updateCommentInfoList(queryString);
}
void ExecSQL::searchCommentInfosForUser(const QString &value)
{
    QString queryString = QString("select * from comment where c_user = '%1'").arg(value);
    qDebug() << queryString;

    updateCommentInfoList(queryString);
}
void ExecSQL::searchCommentInfosForUserAndHotel(const QString &user, const QString& hotel)
{
    QString queryString = QString("select * from comment where c_user = '%1' and c_hotel = '%2'").arg(user).arg(hotel);
    qDebug() << queryString;

    updateCommentInfoList(queryString);
}
void ExecSQL::searchCommentInfosForID(const QString &value)
{
    QString queryString = QString("select * from comment where c_comment = '%1'").arg(value);
    qDebug() << queryString;

    updateCommentInfoList(queryString);
}
void ExecSQL::updateCommentInfoList(const QString &sql)
{
    GlobalVars::g_commentInfoMap.clear();
    GlobalVars::g_commentInfoList->clear();

    QSqlQuery query;
    if(query.exec(sql))
    {
         int comment_idx = query.record().indexOf("c_comment");
         int user_idx = query.record().indexOf("c_user");
         int star_idx = query.record().indexOf("c_star");
         int photo_idx = query.record().indexOf("c_photo");
         int hotel_idx = query.record().indexOf("c_hotel");
         int reserve_idx = query.record().indexOf("c_reserve");

         int hotelName_idx = query.record().indexOf("c_hotel_name");
         int houseType_idx = query.record().indexOf("c_house_type");
         int checkInTime_idx = query.record().indexOf("c_check_in_time");
         int commentTime_idx = query.record().indexOf("c_comment_time");
         int userComment_idx = query.record().indexOf("c_user_comment");
         int hotelComment_idx = query.record().indexOf("c_hotel_comment");

        while(query.next())
        {
            QString comment = query.value(comment_idx).toString();
            QString user = query.value(user_idx).toString();
            QString star = query.value(star_idx).toString();
            QString photo = query.value(photo_idx).toString();
            QString hotel = query.value(hotel_idx).toString();
            QString reserve = query.value(reserve_idx).toString();

            QString hotelName = query.value(hotelName_idx).toString();
            QString houseType = query.value(houseType_idx).toString();
            QString checkInTime = query.value(checkInTime_idx).toString();
            QString commentTime = query.value(commentTime_idx).toString();
            QString userComment = query.value(userComment_idx).toString();
            QString hotelComment = query.value(hotelComment_idx).toString();

//            qDebug() << comment << ", " << user << ", " << star << ", " << hotelName
//                         << ", " << houseType << ", " << checkInTime << ", " << commentTime
//                         << ", "  << userComment << ", " << reserve << ", "  << photo << ", "
//                         << hotelComment;

            CommentInfo info(comment,user,star,hotel,hotelName,houseType, checkInTime,
                             commentTime,userComment,reserve,photo,hotelComment);

            GlobalVars::g_commentInfoList->append(info);
        }

         for(CommentInfoList::iterator it = GlobalVars::g_commentInfoList->begin();
             it != GlobalVars::g_commentInfoList->end(); it++)
         {
            GlobalVars::g_commentInfoMap.insert(it->getComment(), it);
         }
//         qDebug() << GlobalVars::g_commentInfoList->size();
    }
}

bool ExecSQL::modifyCommentInfoForHotelComment(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update comment set c_hotel_comment = '%1' where c_comment = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::modifyCommentInfoForPhoto(const QString &id, const QString &value)
{
    QSqlQuery query;
    QString queryString = QString("update comment set c_photo = '%1' where c_comment = '%2'").arg(value).arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}

bool ExecSQL::deleteCommentInfo(const QString &id)
{
    QSqlQuery query;
    QString queryString = QString("delete from comment where c_comment = '%1'").arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::addNewCommentInfo(const CommentInfo &info)
{
    QSqlQuery query;
    QString queryString = QString("insert into comment "
                                  "(c_comment, c_user, c_star, c_hotel, c_hotel_name, c_house_type, c_check_in_time"
                                  ",c_comment_time, c_user_comment, c_reserve) values('%1', '%2', '%3', '%4', '%5',"
                                  " '%6', '%7', '%8', '%9', '%10')")
                                .arg(info.getComment()).arg(info.getUser()).arg(info.getStar()).arg(info.getHotel())
                                .arg(info.getHotelName()).arg(info.getHouseType()).arg(info.getCheckInTime())
                                .arg(info.getCommentTime()).arg(info.getUserComment()).arg(info.getReserveID());
    qDebug() << queryString;
    return query.exec(queryString);
}


///////////////////////////////////////////////SaveInfo///////////////////////////////////////////////
void ExecSQL::searchAllSaveInfos()
{
    QString queryString = QString("select * from save");
    qDebug() << queryString;
    updateSaveInfoList(queryString);
}
void ExecSQL::searchSaveInfosForUser(const QString &value)
{
    QString queryString = QString("select * from save where s_user = '%1'").arg(value);
    qDebug() << queryString;

    updateSaveInfoList(queryString);
}
void ExecSQL::searchSaveInfosForUserAndHotel(const QString &userID,const QString &hotelID)
{
    QString queryString = QString("select * from save where s_user = '%1' and s_hotel = '%2'").arg(userID).arg(hotelID);
    qDebug() << queryString;

    updateSaveInfoList(queryString);
}
void ExecSQL::searchSaveInfosForID(const QString &value)
{
    QString queryString = QString("select * from save where s_save = '%1'").arg(value);
    qDebug() << queryString;

    updateSaveInfoList(queryString);
}

void ExecSQL::updateSaveInfoList(const QString &sql)
{
    GlobalVars::g_saveInfoMap.clear();
    GlobalVars::g_saveInfoList->clear();

    QSqlQuery query;
    if(query.exec(sql))
    {
         int save_idx = query.record().indexOf("s_save");
         int user_idx = query.record().indexOf("s_user");
         int hotel_idx = query.record().indexOf("s_hotel");

        while(query.next())
        {
            QString save = query.value(save_idx).toString();
            QString user = query.value(user_idx).toString();
            QString hotel = query.value(hotel_idx).toString();

            qDebug() << save << ", " << user << ", " << hotel;

            SaveInfo info(save,user,hotel);

            GlobalVars::g_saveInfoList->append(info);
        }

         for(SaveInfoList::iterator it = GlobalVars::g_saveInfoList->begin();
             it != GlobalVars::g_saveInfoList->end(); it++)
         {
            GlobalVars::g_saveInfoMap.insert(it->getSave(), it);
         }
//         qDebug() << GlobalVars::g_saveInfoList->size();
    }
}

bool ExecSQL::deleteSaveInfo(const QString &id)
{
    QSqlQuery query;
    QString queryString = QString("delete from save where s_save = '%1'").arg(id);
    qDebug() << queryString;
    return query.exec(queryString);
}
bool ExecSQL::addNewSaveInfo(const SaveInfo &info)
{
    QSqlQuery query;
    QString queryString = QString("insert into save "
                                  "(s_save, s_user, s_hotel) values('%1', '%2', '%3')")
                                .arg(info.getSave()).arg(info.getUser()).arg(info.getHotel());
    qDebug() << queryString;
    return query.exec(queryString);
}
